package com.example.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * Description:
 * User: 阿宾
 * Date: 2025-04-29
 * Time: 19:40
 */
@Slf4j
@Component
@Aspect //表示当前类是一个切面类
public class MyAspectDemo {
    //环绕通知
    //自定义注解，使用注解annotation来标识自定义注解位置，需要使用自定义注解的全类名
    @Around("@annotation(com.example.config.MyAspect)")
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("MyAspectDemo Around 方法开始执行");
        Object result = null;
        try{
            result = joinPoint.proceed();
        }catch (Exception e){
            log.error("发生异常，e",e);
        }

        log.info("MyAspectDemo Around 方法结束执行");
        return result;
    }

    /*@Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public Object doAround1(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("RequestMapping Around 方法开始执行");
        Object result = null;
        try{
            result = joinPoint.proceed();
        }catch (Exception e){
            log.error("发生异常，e",e);
        }

        log.info("RequestMapping Around 方法结束执行");
        return result;
    }*/
}
